using System;
using System.Web.UI.WebControls;

namespace Quaack.Web.Controls
{
    public class ButtonHolder
    {
        private readonly Button _button;

        private ButtonType _type;

        public ButtonType Type
        {
            get { return _type; }
            set
            {
                _type = value;
                SetButtonType(_type);
            }
        }

        public ButtonHolder(Button button)
        {
            _button = button;
            _button.Click += OnButtonClicked;

            Type = ButtonType.Undefined;
            
        }

        private void OnButtonClicked(object sender, EventArgs e)
        {
            OnButtonClicked(e);
        }


        public delegate void ButtonClickedEventHandler(object sender, EventArgs e);

        public event ButtonClickedEventHandler ButtonClicked;

        protected virtual void OnButtonClicked(EventArgs e)
        {
            if (ButtonClicked != null)
                ButtonClicked(this, e);
        }

        private void SetButtonType(ButtonType type)
        {
            switch (type)
            {
                case ButtonType.Undefined:
                    {
                        _button.Text = "";
                        _button.Enabled = false;
                        _button.Visible = false;
                        break;
                    }

                //RemoveProfile = 1,
                case ButtonType.RemoveProfile:
                    {
                        _button.Text = "Verwijder";
                        _button.Enabled = true;
                        _button.Visible = true;
                        break;
                    }

                //RemoveMessage = 2,
                case ButtonType.RemoveMessage:
                    {
                        _button.Text = "Verwijder";
                        _button.Enabled = true;
                        _button.Visible = true;
                        break;
                    }

                //RemoveUser = 3,
                case ButtonType.RemoveUser:
                    {
                        _button.Text = "Verwijder";
                        _button.Enabled = true;
                        _button.Visible = true;
                        break;
                    }


                //EditMessage = 4,
                case ButtonType.EditMessage:
                    {
                        _button.Text = "Bewerk";
                        _button.Enabled = true;
                        _button.Visible = true;
                        break;
                    }

                //EditProfile = 5,
                case ButtonType.EditProfile:
                    {
                        _button.Text = "Bewerk";
                        _button.Enabled = true;
                        _button.Visible = true;
                        break;
                    }

                //BlockUser = 6,
                case ButtonType.BlockUser:
                    {
                        _button.Text = "Blokkeer";
                        _button.Enabled = true;
                        _button.Visible = true;
                        break;
                    }

                //DeBlockUser = 7,
                case ButtonType.DeBlockUser:
                    {
                        _button.Text = "Deblokkeer";
                        _button.Enabled = true;
                        _button.Visible = true;
                        break;
                    }

                //PostNewMessage = 8,
                case ButtonType.PostNewMessage:
                    {
                        _button.Text = "Nieuw bericht";
                        _button.Enabled = true;
                        _button.Visible = true;
                        break;
                    }

                //PostResponseMessage = 9,
                case ButtonType.PostResponseMessage:
                    {
                        _button.Text = "Reageer";
                        _button.Enabled = true;
                        _button.Visible = true;
                        break;
                    }

                //NavigateHome = 10
                case ButtonType.NavigateHome:
                    {
                        _button.Text = "Home";
                        _button.Enabled = true;
                        _button.Visible = true;
                        break;
                    }
                //SaveMessage = 11
                case ButtonType.SaveMessage:
                    {
                        _button.Text = "Opslaan";
                        _button.Enabled = true;
                        _button.Visible = true;
                        break;
                    }
                //CancelMessage = 12
                case ButtonType.CancelMessage:
                    {
                        _button.Text = "Annuleren";
                        _button.Enabled = true;
                        _button.Visible = true;
                        break;
                    }
                case ButtonType.BlockProfile:
                    {
                        _button.Text = "Blokkeer login";
                        _button.Enabled = true;
                        _button.Visible = true;
                        break;
                    }
                case ButtonType.DeblockProfile:
                    {
                        _button.Text = "Deblokkeer login";
                        _button.Enabled = true;
                        _button.Visible = true;
                        break;
                    }
                default:
                    {
                        _button.Text = "";
                        _button.Enabled = false;
                        _button.Visible = false;
                        break;
                    }
            }
        }
    }
}